package com.jsoft.controller;

import com.jsoft.entity.Industry;
import com.jsoft.entity.PageBean;
import com.jsoft.service.IndustryService;
import com.jsoft.util.Result;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * (Industry)表控制层
 *
 * @author makejava
 * @since 2025-03-14 23:30:25
 */
@RestController
@RequestMapping("industry")
public class IndustryController {
    /**
     * 服务对象
     */
    @Resource
    private IndustryService industryService;

    /**
     * 分页查询
     *
     * @param industry 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Industry>> queryByPage(Industry industry, PageRequest pageRequest) {
        return ResponseEntity.ok(this.industryService.queryByPage(industry, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Industry> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.industryService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param industry 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Industry> add(Industry industry) {
        return ResponseEntity.ok(this.industryService.insert(industry));
    }

    /**
     * 编辑数据
     *
     * @param industry 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Industry> edit(Industry industry) {
        return ResponseEntity.ok(this.industryService.update(industry));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.industryService.deleteById(id));
    }

    /**
     * 通过id查询行业信息
     * @param pageNum
     * @param pageSize
     * @param id
     * @return
     */
    @GetMapping("/industryById")
    public Result<PageBean<Industry>> queryIndustryById(@RequestParam @NotNull Integer pageNum,
                                                        @RequestParam @NotNull Integer pageSize,
                                                        @NotEmpty Integer id){

        PageBean<Industry> pb = industryService.queryIndustryById(pageNum,pageSize,id);
        return Result.success(pb);



    }

    /**
     * 查询所有行业的信息
     * @return
     */
    @GetMapping("/all")
    public Result<List<Industry>> queryall(){

       List<Industry> list =  industryService.queryall();
       return Result.success(list);

    }


}

